package org.example.entity;

import org.example.common.SerializationInterface;

public class Calculatepojo implements SerializationInterface<Calculatepojo> {
    private Integer id;
    private Boolean success;
    private String msg;
    private Double numLeft;
    private Double numRight;
    private String operator;
    private Double result;

    public void protoToPojo(CalculateProto.Calculate proto) {
        this.id = proto.getId();
        this.success = proto.getSuccess();
        this.msg = proto.getMsg();
        this.numLeft = proto.getNumLeft();
        this.numRight = proto.getNumRight();
        this.operator = proto.getOperator();
        this.result = proto.getResult();
    }

    public CalculateProto.Calculate pojoToProto(Calculatepojo pojo) {
        CalculateProto.Calculate.Builder calculate = CalculateProto.Calculate.newBuilder();
        calculate.setId(pojo.getId());
        calculate.setSuccess(pojo.getSuccess());
        calculate.setMsg(pojo.getMsg());
        calculate.setNumLeft(pojo.getNumLeft());
        calculate.setNumRight(pojo.getNumRight());
        calculate.setOperator(pojo.getOperator());
        calculate.setResult(pojo.getResult());
        return calculate.build();
    }



    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Double getNumLeft() {
        return numLeft;
    }

    public void setNumLeft(Double numLeft) {
        this.numLeft = numLeft;
    }

    public Double getNumRight() {
        return numRight;
    }

    public void setNumRight(Double numRight) {
        this.numRight = numRight;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }

    public Double getResult() {
        return result;
    }

    public void setResult(Double result) {
        this.result = result;
    }

    @Override
    public byte[] toSerialization(Calculatepojo calculatepojo) {
        CalculateProto.Calculate calculate = this.pojoToProto(calculatepojo);
        return calculate.toByteArray();
    }

    @Override
    public Calculatepojo reverseSerialization(byte[] input) throws Exception {
        CalculateProto.Calculate calculate = null;
        calculate = CalculateProto.Calculate.parseFrom(input);
        this.protoToPojo(calculate);
        return this;
    }
}
